using Common.Commands.ContactCommands;
using Common.Enumerations;
using Common.Views;
using Core.Domain.Model;
using NUnit.Framework;
using Sanelib.Common.Extensions;
using Sanelib.Common.Helpers;
using Sanelib.DataView;

namespace IntegrationTests.Processors
{
    public class AssignedContactProcessorTester : IntegrationTestBase
    {
        [Test]
        public void ShouldAddAssignedContact()
        {
            var contact = new Contact
            {
                Id = GuidComb.New(),
                Name = "NikunjBBalar",
                NameTitle = NameTitle.Mr,
                LastName = "Nikunj",
                FirstName = "Balar",
                Email = "niksunjbbalar@gmail.com",
                Phone = "9099791517",
                Mobile = "9099791517",
                CompanyName = "Sanelib Software Solutions",
                Designation = Designation.De,
                Description = "He is good man.",
                ImageData = ImageUtility.NoImageData
            };

            var account = new Account
            {
                Id = GuidComb.New(),
                Name = "Priya",
                AccountType = AccountType.Vendor,
                AccountNumber = "accountnumber",
                Industry = Industry.Electronics,
                BillingStreet = "billingstreet",
                BillingCity = "city",
                BillingState = "state",
                BillingPostalCode = "code",
                BillingCountry = "county",
                BillingLatitude = 0,
                BillingLongitude = 0,
                ShippingStreet = "sstreet",
                ShippingCity = "scity",
                ShippingState = "sstate",
                ShippingPostalCode = "Scode",
                ShippingCountry = "scountry",
                ShippingLatitude = 0,
                ShippingLongitude = 0,
                Phone = "phone",
                Mobile = "mobile",
                Fax = "fax",
                Website = "web",
                Email = "email@email.com",
                Description = "Description",
                ImageData = ImageUtility.NoImageData
            };

            Persist(contact, account);

            var command = new AddAssignedContact
            {
                Id = GuidComb.New(),
                Name = "NikunjBBalar",
                ContactId = contact.Id,
                EntityType = EntityType.Account,
                ReferenceName = account.Name,
                ReferenceId = account.Id,
                ImageData = ImageUtility.NoImageData,
                Description = "With 1 year experiance in C# .net MVC",
            };
            ProcessCommand(command);
            var repo = GetInstance<IViewRepository<AssignedContactView>>();
            var assignedContactView = repo.GetById(command.Id);

            Assert.AreEqual(assignedContactView.Name, command.Name);
        }

        [Test]
        public void ShouldDeleteAssignedContact()
        {
            var contact = new Contact
            {
                Id = GuidComb.New(),
                Name = "NikunjBBalar",
                NameTitle = NameTitle.Mr,
                LastName = "Nikunj",
                FirstName = "Balar",
                Email = "niksunjbbalar@gmail.com",
                Phone = "9099791517",
                Mobile = "9099791517",
                CompanyName = "Sanelib Software Solutions",
                Designation = Designation.De,
                Description = "He is good man.",
                ImageData = ImageUtility.NoImageData
            };

            var assignedcontact = new AssignedContact
            {
                Id = GuidComb.New(),
                Name = "NikunjBBalar",
                ContactId = contact.Id,
                EntityType = EntityType.Contact,
                ReferenceName = contact.Name,
                ReferenceId = contact.Id,
                ImageData = ImageUtility.NoImageData,
                Description = "With 1 year experiance in C# .net MVC",
            };

            Persist(assignedcontact, contact);

            var command = new DeleteAssignedContact(assignedcontact.Id);
            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<AssignedContactView>>();
            var assignedContactView = repo.GetById(command.Id);

            Assert.IsNull(assignedContactView);
        }

        [Test]
        public void ShouldUpdateAssignedContact()
        {
            var contact = new Contact
            {
                Id = GuidComb.New(),
                Name = "NikunjBBalar",
                NameTitle = NameTitle.Mr,
                LastName = "Nikunj",
                FirstName = "Balar",
                Email = "niksunjbbalar@gmail.com",
                Phone = "9099791517",
                Mobile = "9099791517",
                CompanyName = "Sanelib Software Solutions",
                Designation = Designation.De,
                Description = "With 1 yeat experiance in c#. net MVC",
                ImageData = ImageUtility.NoImageData
            };

            var assignedcontact = new AssignedContact
            {
                Id = GuidComb.New(),
                Name = "NikunjBBalar",
                ContactId = GuidComb.New(),
                EntityType = EntityType.Contact,
                ReferenceName = contact.Name,
                ReferenceId = contact.Id,
                ImageData = ImageUtility.NoImageData,
                Description = "With 1 year experiance in C# .net MVC",
            };

            Persist(contact, assignedcontact);

            var command = new UpdateAssignedContact
            {
                Id = assignedcontact.Id,
                Name = "NikunjBBalar",
                ContactId = contact.Id,
                EntityType = EntityType.Contact,
                ReferenceName = contact.Name,
                ReferenceId = contact.Id,
                ImageData = ImageUtility.NoImageData,
                Description = "With 1 year experiance in C# .net MVC",
            };
            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<AssignedContactView>>();
            var assignedContactView = repo.GetById(command.Id);

            Assert.AreEqual(assignedContactView.Id, assignedcontact.Id);
        }
    }
}